package pkg

import (
	openapi "github.com/alibabacloud-go/darabonba-openapi/client"
	dysmsapi20170525 "github.com/alibabacloud-go/dysmsapi-20170525/v2/client"
	"github.com/alibabacloud-go/tea/tea"
	"strconv"
)

/**
 * 使用AK&SK初始化账号Client
 * @param accessKeyId
 * @param accessKeySecret
 * @return Client
 * @throws Exception
LTAI5tPC9YXDVkuNNbFGqiBk
RAtemW3sZGEFtKDqSnpZZOnhcV47RF
*/
func CreateClient(accessKeyId *string, accessKeySecret *string) (_result *dysmsapi20170525.Client, _err error) {
	config := &openapi.Config{
		// 您的AccessKey ID
		AccessKeyId: accessKeyId,
		// 您的AccessKey Secret
		AccessKeySecret: accessKeySecret,
	}
	// 访问的域名
	config.Endpoint = tea.String("dysmsapi.aliyuncs.com")
	_result = &dysmsapi20170525.Client{}
	_result, _err = dysmsapi20170525.NewClient(config)
	return _result, _err
}

func SendMessage(args []*string, vcode string, phoneNum int) (_err error) {
	client, _err := CreateClient(tea.String("LTAI5tPC9YXDVkuNNbFGqiBk"), tea.String("RAtemW3sZGEFtKDqSnpZZOnhcV47RF"))
	if _err != nil {
		return _err
	}
	sendSmsRequest := &dysmsapi20170525.SendSmsRequest{
		PhoneNumbers:  tea.String(strconv.Itoa(phoneNum)), //电话号码
		SignName:      tea.String("传啊宇三"),                 //短信签名
		TemplateCode:  tea.String("SMS_185840383"),
		TemplateParam: tea.String("{code:" + vcode + "}"),
	}
	// 复制代码运行请自行打印 API 的返回值
	_, _err = client.SendSms(sendSmsRequest)
	if _err != nil {
		return _err
	}
	return _err
}
